<?php

namespace app\librarys;

class InterfaceService
{
    /**
     * auth系统api访问请求
     * @param $api_path
     * @param $post_params
     * @return mixed|string
     */
    public static function requestAuthApi($api_path, $post_params)
    {
        $url = \Yii::$app->params['auth.api.address'] . $api_path;
        $account = \Yii::$app->params['auth.api.account'];
        $token = \Yii::$app->params['auth.api.token'];

        $item = Tools::postApi($url, $account, $token, $post_params);
        return json_decode($item);
    }

    /**
     * 访问messager API接口
     * @param string $api_path
     * @param mixed $post_params
     * @return string
     */
    public static function requestMessagerApi($post_params, $api_path = 'sms/send-sms')
    {
        $url = \Yii::$app->params['messager.api.address'] . $api_path;
        $account = \Yii::$app->params['messager.api.account'];
        $token = \Yii::$app->params['messager.api.token'];
        $data = Tools::postApi($url, $account, $token, $post_params);
        return json_decode($data);
    }

    /**
     * query系统api访问请求
     * @param $api_path
     * @param $post_params
     * @return mixed|string
     */
    public static function requestQueryApi($api_path, $post_params)
    {
        $url = \Yii::$app->params['query.api.address'] . $api_path;
        $account = \Yii::$app->params['query.api.account'];
        $token = \Yii::$app->params['query.api.token'];

        $item = Tools::postApi($url, $account, $token, $post_params);
        return json_decode($item);
    }

    /**
     * push系统api访问请求
     * @param $api_path
     * @param $post_params
     * @return mixed|string
     */
    public static function requestPushApi($api_path, $post_params)
    {
        $url = \Yii::$app->params['push.api.address'] . $api_path;
        $account = \Yii::$app->params['push.api.account'];
        $token = \Yii::$app->params['push.api.token'];

        $item = Tools::postApi($url, $account, $token, $post_params);
        return json_decode($item);
    }
}